<!DOCTYPE html>
<title>Credential Manager: FederatedCredential basics.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
test(function() {
    var credential = new FederatedCredential({
        'id': 'id',
        'provider': 'https://federation.test/',
        'name': 'name',
        'iconURL': 'https://example.test/icon.png'
    });

    assert_equals(credential.id, 'id');
    assert_equals(credential.name, 'name');
    assert_equals(credential.iconURL, 'https://example.test/icon.png');
    assert_equals(credential.provider, 'https://federation.test');
    assert_equals(credential.type, 'federated');
}, 'Creating FederatedCredential with all arguments specified should succeed.');

test(function() {
    var credential = new FederatedCredential({
        'id': 'id',
        'provider': 'https://federation.test/',
        'name': 'name'
    });

    assert_equals(credential.id, 'id');
    assert_equals(credential.name, 'name');
    assert_equals(credential.iconURL, '');
    assert_equals(credential.provider, 'https://federation.test');
    assert_equals(credential.type, 'federated');
}, 'Creating FederatedCredential without |iconURL| should succeed.');

test(function() {
    var credential = new FederatedCredential({
        'id': 'id',
        'provider': 'https://federation.test/',
    });

    assert_equals(credential.id, 'id');
    assert_equals(credential.name, '');
    assert_equals(credential.iconURL, '');
    assert_equals(credential.provider, 'https://federation.test');
    assert_equals(credential.type, 'federated');
}, 'Creating FederatedCredential without |iconURL| and |name| should succeed.l');

test(function() {
    assert_throws_dom("SyntaxError", function () {
        var credential = new FederatedCredential({
            'id': 'id',
            'provider': 'https://federation.test/',
            'name': 'name',
            'iconURL': '-'
        });
    });
}, 'Construct a FederatedCredential with an invalid Icon URL.');

test(function() {
    assert_throws_dom("SyntaxError", function () {
        var credential = new FederatedCredential({
            'id': 'id',
            'provider': '-',
            'name': 'name',
            'iconURL': 'https://example.test/icon.png'
        });
    });
}, 'Construct a FederatedCredential with an invalid federation URL.');

test(function() {
    assert_throws_js(TypeError,
                     () => { new FederatedCredential(); });
    assert_throws_js(TypeError,
                     () => { new FederatedCredential({}); });
    assert_throws_js(TypeError,
                     () => { new FederatedCredential({ 'id': undefined }); });
    assert_throws_js(TypeError,
                     () => { new FederatedCredential({ 'id': '' }); });
    assert_throws_js(TypeError,
                     () => { new FederatedCredential({ 'provider': undefined }); });
    assert_throws_js(TypeError,
                     () => { new FederatedCredential({ 'provider': '' }); });
    assert_throws_js(TypeError,
                     () => { new FederatedCredential({ 'id': undefined, 'provider': undefined }); });
    assert_throws_js(TypeError,
                     () => { new FederatedCredential({ 'id': undefined, 'provider': '' }); });
    assert_throws_js(TypeError,
                     () => { new FederatedCredential({ 'id': undefined, 'provider': undefined }); });
}, 'FederatedCredential objects require IDs and Providers');
</script>
